﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using Padelcenter.Common;

namespace Padelcenter.DataAccess
{
    #region Moneda Select

    public class Moneda_Select : DataAccessBase
    {
        #region Private Vars
        
        private Moneda _Moneda;
        private bool _Disposed = false;
        
        #endregion

        #region Properties

        public Moneda Moneda
        {
            get { return _Moneda; }
            set { _Moneda = value; }
        }
        #endregion

        #region Constructor

        public Moneda_Select()
        {
            StoredProcedureName = StoredProcedure.Name.Moneda_SELECT.ToString();
        }

        ~Moneda_Select()
        {
            this.Dispose(false);
        }
        #endregion

        #region Public Methods

        public DataSet Get()
        {
            DataSet ds = null;
            Moneda_Select_Prm moneda_Select_Prm = null;
            DataBaseHelper dbhelper = null;
           
            try
            {
                moneda_Select_Prm = new Moneda_Select_Prm(this.Moneda);
                dbhelper = new DataBaseHelper(StoredProcedureName);
                ds = dbhelper.Run(base.ConnectionString, moneda_Select_Prm.Parameters);

                return ds;
            }
            catch (Exception e)
            {
                // Common Exception
                throw (new Exception("Moneda_Select.Get: " + e.Message.ToString()));
            }
            finally
            {
                if (ds != null)
                    ds.Dispose();
                ds = null;
                
                moneda_Select_Prm = null;
                dbhelper = null;               
            }
        }
        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            this.Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposable)
        {
            if (!this._Disposed)
            {
                if (disposable)
                {
                    ReleaseManagedResources();
                }
                ReleaseUnmanagedResources();
            }
            _Disposed = true;
        }

        /// Release unmanaged resources
        protected virtual void ReleaseUnmanagedResources()
        {
            if (_Moneda != null)
                _Moneda.Dispose();
            _Moneda = null;

        }

        /// Release managed resources		
        protected virtual void ReleaseManagedResources()
        {
        }

        #endregion
    }

    public class Moneda_Select_Prm
    {
        #region Private Vars

        private Moneda _Moneda = null;
        private SqlParameter[] _parameters = null;

        #endregion

        #region Properties

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        public Moneda Moneda
        {
            get { return _Moneda; }
            set { _Moneda = value; }
        }

        #endregion

        #region Constructor

        public Moneda_Select_Prm(Moneda moneda)
        {
            this.Moneda = moneda;
            this.BuildParams();
        }

        #endregion

        #region Private Methods

        private void BuildParams()
        {
            try
            {
                SqlParameter[] parameters = 
                {
                    new SqlParameter( "@idMoneda"           , this.Moneda.IdMoneda ),
                    new SqlParameter( "@ConFiltroActivo"    , this.Moneda.ConFiltroActivo),
                    new SqlParameter( "@Activo"             , this.Moneda.Activo)
                };

                this.Parameters = parameters;
            }
            catch (Exception e)
            {
                // Common Exception
                throw (new Exception("Moneda_Select_Prm.BuildParams: " + e.Message.ToString()));
            }
        }
        #endregion
    }
    #endregion

    #region " Moneda Insert "
    public class Moneda_Insert : DataAccessBase
    {
        public Moneda_Insert()
        {
            StoredProcedureName = StoredProcedure.Name.Moneda_INSERT.ToString();
        }

        public DataSet Get()
        {
            DataSet ds;

            Moneda_Insert_Prm moneda_Insert_Prm = new Moneda_Insert_Prm(this.Moneda);
            DataBaseHelper dbhelper = new DataBaseHelper(StoredProcedureName);
            ds = dbhelper.Run(base.ConnectionString, moneda_Insert_Prm.Parameters);

            return ds;
        }

        private Moneda _moneda;

        public Moneda Moneda
        {
            get { return _moneda; }
            set { _moneda = value; }
        }
    }

    public class Moneda_Insert_Prm
    {
        public Moneda_Insert_Prm(Moneda moneda)
        {
            this.Moneda = moneda;
            this.BuildParams();
        }

        private void BuildParams()
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter( "@Descripcion"        , this.Moneda.Descripcion),
                new SqlParameter( "@Cotizacion"         , this.Moneda.Cotizacion),
                new SqlParameter( "@Simbolo"            , this.Moneda.Simbolo),
                new SqlParameter( "@Activo"             , this.Moneda.Activo)
            };

            this.Parameters = parameters;
        }

        private Moneda _moneda;
        private SqlParameter[] _parameters;

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        public Moneda Moneda
        {
            get { return _moneda; }
            set { _moneda = value; }
        }
    }
    #endregion

    #region " Moneda Update "
    public class Moneda_Update : DataAccessBase
    {
        public Moneda_Update()
        {
            StoredProcedureName = StoredProcedure.Name.Moneda_UPDATE.ToString();
        }

        public DataSet Get()
        {
            DataSet ds;

            Moneda_Update_Prm moneda_Update_Prm = new Moneda_Update_Prm(this.Moneda);
            DataBaseHelper dbhelper = new DataBaseHelper(StoredProcedureName);
            ds = dbhelper.Run(base.ConnectionString, moneda_Update_Prm.Parameters);

            return ds;
        }

        private Moneda _moneda;

        public Moneda Moneda
        {
            get { return _moneda; }
            set { _moneda = value; }
        }
    }

    public class Moneda_Update_Prm
    {
        public Moneda_Update_Prm(Moneda moneda)
        {
            this.Moneda = moneda;
            this.BuildParams();
        }

        private void BuildParams()
        {
            SqlParameter[] parameters = 
            {
                new SqlParameter( "@idMoneda"           , this.Moneda.IdMoneda),
                new SqlParameter( "@Descripcion"        , this.Moneda.Descripcion),
                new SqlParameter( "@Cotizacion"         , this.Moneda.Cotizacion),
                new SqlParameter( "@Simbolo"            , this.Moneda.Simbolo),
                new SqlParameter( "@Activo"             , this.Moneda.Activo)
            };

            this.Parameters = parameters;
        }

        private Moneda _moneda;
        private SqlParameter[] _parameters;

        public SqlParameter[] Parameters
        {
            get { return _parameters; }
            set { _parameters = value; }
        }

        public Moneda Moneda
        {
            get { return _moneda; }
            set { _moneda = value; }
        }
    }
    #endregion
}
